﻿package com.CrmDemo.services;

import java.io.Serializable;
import java.util.List;

import org.hibernate.SessionFactory;


import com.CrmDemo.util.*;

import com.CrmDemo.dao.CommonDAO;
import com.CrmDemo.entity.BasDict;
import com.CrmDemo.entity.CstCustomer;


public class DictService extends BaseService {
	
	
	
	
	
	/*   简单业务方法    */
	/**
	 * 加载 
	 */
	public BasDict get(Serializable id){
		BasDict ret = (BasDict)this.getCommonDAO().get(BasDict.class, id);		
		return ret;
	}
	
	/**
	 * 添加 
	 */
	public boolean add(BasDict item){
		this.getCommonDAO().add(item);		
		return true;
	}
	
	/**
	 * 删除 
	 */
	public boolean del(Serializable id){
		this.getCommonDAO().del(BasDict.class, id);		
		return true;
	}
	
	/**
	 * 修改 
	 */
	public boolean update(BasDict item){
		this.getCommonDAO().update(item);		
		return true;
	}
	
	/**
	 * 查询  
	 */
	public void search(BasDict condition, PageResult pageResult) {
		String hql = "select o from BasDict o where 1=1 ";
		if (null!=condition){				
				if (isNotNullOrEmpty(condition.getDictType())){
				hql += "and o.dictType like '%"
						+condition.getDictType()+"%' ";
			}

				if (isNotNullOrEmpty(condition.getDictItem())){
				hql += "and o.dictItem like '%"
						+condition.getDictItem()+"%' ";
			}

				if (isNotNullOrEmpty(condition.getDictValue())){
				hql += "and o.dictValue like '%"
						+condition.getDictValue()+"%' ";
			}

			
		}
		if (isNotNullOrEmpty(pageResult.getOrderBy())){
			String sort = pageResult.getSort();
			hql += "order by " + pageResult.getOrderBy() + " " +sort; 
			if ("asc".equals(sort)){
				pageResult.setSort("desc");
			}else{
				pageResult.setSort("asc");
			}
		}else{
			hql += "order by o.dictId desc";
		}		
		this.getCommonDAO().listByPage(hql,pageResult);
	}

	public List getList(String type) {
		String hql = "select o from BasDict o where o.dictType='"+type+"' ";
		return this.getCommonDAO().list(hql);
	}
}
